//
//  KSTabBarController.m
//  BasketBallLeagues
//
//  Created by kenshin on 4/23/17.
//  Copyright © 2017 kenshin. All rights reserved.
//

#import "KSTabBarController.h"

#import "SKTHomeViewController.h"
#import "SKTIssueViewController.h"
#import "SKTListViewController.h"
#import <Photos/Photos.h>

@interface KSTabBarController () <UITabBarControllerDelegate>
@property (nonatomic, strong) UITabBarItem *lastItem;

@end

@implementation KSTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName: [BLColorConfig blackColor], NSFontAttributeName: [UIFont systemFontOfSize:12.f]} forState:UIControlStateNormal];

    [self configTabBar];
    self.delegate = self;
    UIImage *image = [UIImage jc_createImageWithColor:[BLColorConfig lineColor]];
    image = [image jc_scaleToSize:CGSizeMake([UIWindow ks_screenWidth], 1.f/[UIScreen mainScreen].scale)];
    [self.tabBar setShadowImage:image];
    image = [UIImage jc_createImageWithColor:[UIColor whiteColor]];
    image = [image jc_scaleToSize:CGSizeMake([UIWindow ks_screenWidth], 49)];
    [self.tabBar setBackgroundImage:image];
//    if ([[BLMessageManager sharedInstance] hasMessageNotRead]) {
//        [self setupTabbarBadge];
//    }

}



- (void)configTabBar
{
    SKTHomeViewController *homepageVC = [[SKTHomeViewController alloc] init];
    homepageVC.title = @"首页";
    KSNavigationController *homepageNavi = [[KSNavigationController alloc] initWithRootViewController:homepageVC];
    [self configTabbarItem:homepageVC.tabBarItem
                     image:[UIImage imageNamed:@"tab_home"]
             selectedImage:[UIImage imageNamed:@"tab_home_sel"]];
    
    SKTIssueViewController *classifyVC = [[SKTIssueViewController alloc] init];
    
    KSNavigationController *classifyNavi = [[KSNavigationController alloc] initWithRootViewController:classifyVC];
    [self configTabbarItem:classifyVC.tabBarItem
                     image:[UIImage imageNamed:@"tab_ issue"]
             selectedImage:nil];
    
    
    SKTListViewController *mineVC = [[SKTListViewController alloc] init];
    mineVC.title = @"我的";
    KSNavigationController *mineNavi = [[KSNavigationController alloc] initWithRootViewController:mineVC];
    [self configTabbarItem:mineVC.tabBarItem
                     image:[UIImage imageNamed:@"tab_center"]
             selectedImage:[UIImage imageNamed:@"tab_center_sel"]];
    
    self.viewControllers = @[homepageNavi, classifyNavi, mineNavi];
     
}

- (void)configTabbarItem:(UITabBarItem *)tabBarItem
                   image:(UIImage *)image
           selectedImage:(UIImage *)selectedImage
{
    tabBarItem.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
    tabBarItem.selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}

#pragma mark - UITabBarControllerDelegate

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
//    if ([self.viewControllers indexOfObject:viewController] == 1) {
//        SKTIssueViewController *publishVC = [[SKTIssueViewController alloc] init];
//        [UIViewController ks_pushViewController:publishVC animated:NO];
//        return NO;
//    }
    
    if (self.shouldSelectTabIndex) {
        return self.shouldSelectTabIndex([self.viewControllers indexOfObject:viewController]);
    }
    return YES;

}




@end
